package com.atguigu.study.config;

import com.atguigu.study.service.ChatAssistant;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.time.Duration;

@Configuration(proxyBeanMethods = false)
public class ChatLanguageModelConfig {
    @Bean
    public StreamingChatModel streamingChatModel() {
        return OpenAiStreamingChatModel.builder()
            .apiKey(System.getenv("LANGCHAIN4J_KEY"))
            .modelName("qwen-turbo")
            .timeout(Duration.ofSeconds(10))
            .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
            .build();
    }

    @Bean
    @Primary
    public StreamingChatModel streamingChatModelWithDeepSeek() {
        return OpenAiStreamingChatModel.builder()
            .apiKey("sk-d8c3724e7a4b4d18932852dae9d90c69")
            .modelName("deepseek-chat")
            .baseUrl("https://api.deepseek.com/v1")
            .build();
    }

    @Bean
    public ChatAssistant chatAssistant(StreamingChatModel streamingChatModel) {
        return AiServices.create(ChatAssistant.class, streamingChatModel);
    }

}
